import openpyxl


class ReadExcel:
    @staticmethod
    def read_excel(file_path, sheet_name):
        # 打开Excel文件
        workbook = openpyxl.load_workbook(file_path)
        # 获取指定工作表
        sheet = workbook[sheet_name]
        # 获取工作表中的数据
        data = [[sheet.cell(row=i, column=j).value for j in range(1, sheet.max_column + 1)] for i in
                range(2, sheet.max_row + 1)]
        return data


def main():
    try:
        print("尝试读取文件")
        file_path = "output.xlsx"
        sheet_name = "Sheet"
        data = ReadExcel.read_excel(file_path, sheet_name)
        print(data)
    except FileNotFoundError:
        print(f"文件 {file_path} 未找到")
        try:
            print("尝试创建文件")
            workbook = openpyxl.Workbook()
            workbook.save(file_path)
            print("文件创建成功")
        except Exception as e:
            print(f"创建文件失败 {str(e)}")
    except Exception as e:
        print(f"读取文件时发生错误 {str(e)}")


if __name__ == '__main__':
    main()
